package com.zfc.life.controller.backend;

import com.github.pagehelper.PageInfo;
import com.zfc.life.comm.AjaxResult;
import com.zfc.life.comm.BaseUserInfo;
import com.zfc.life.domain.Beautiful;
import com.zfc.life.domain.Resource;
import com.zfc.life.service.BeautifulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author zfc
 * @Date 2024/8/15 13:04
 * @Description BeautifulController
 */
@Controller
@RequestMapping("/backend/beautiful")
public class BeautifulController {

    @Autowired
    private BeautifulService beautifulService;

    @GetMapping("/listBeautiful")
    @ResponseBody
    public AjaxResult listBeautiful(Integer pageNum, Integer pageSize) {
        if (StringUtils.isEmpty(pageNum) || pageNum <= 1) {
            pageNum = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize <= 10 || pageSize >= 100) {
            pageSize = 10;
        }
        PageInfo<Resource> listResource = beautifulService.listBeautiful(pageNum, pageSize);
        return AjaxResult.success(listResource);
    }

    @PostMapping("/addBeautiful")
    @ResponseBody
    public AjaxResult addBeautiful(@RequestBody Beautiful beautiful) {

        return AjaxResult.success(beautifulService.addBeautiful(beautiful));
    }

    @PutMapping("/modifyBeautiful")
    @ResponseBody
    public AjaxResult modifyBeautiful(@RequestBody Beautiful beautiful) {
        return AjaxResult.success(beautifulService.modifyBeautiful(beautiful));
    }

    @DeleteMapping("/deleteBeautiful/{id}")
    @ResponseBody
    public AjaxResult deleteBeautiful(@PathVariable Long id) {
        return AjaxResult.success(beautifulService.deleteBeautiful(id));
    }
}
